<html>
<head><meta charset="utf-8"><title>Why aren&#x27;t `extern &quot;C&quot; fn` declarations checked for FFI s... · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Why.20aren&#x27;t.20.60extern.20.22C.22.20fn.60.20declarations.20checked.20for.20FFI.20s.2E.2E.2E.html">Why aren&#x27;t `extern &quot;C&quot; fn` declarations checked for FFI s...</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187244776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Why%20aren%27t%20%60extern%20%22C%22%20fn%60%20declarations%20checked%20for%20FFI%20s.../near/187244776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Why.20aren&#x27;t.20.60extern.20.22C.22.20fn.60.20declarations.20checked.20for.20FFI.20s.2E.2E.2E.html#187244776">(Feb 03 2020 at 09:15)</a>:</h4>
<p>Given an example function declaration like</p>
<div class="codehilite"><pre><span></span><span class="cp">#[no_mangle]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">echo</span><span class="p">(</span><span class="n">words</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">str</span> <span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">words</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>Rust doesn't report the function as using types that aren't safe for FFI. Really, it should.</p>
<p>Is this some sort of intentionally decided gap in the linting?</p>



<a name="187253936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Why%20aren%27t%20%60extern%20%22C%22%20fn%60%20declarations%20checked%20for%20FFI%20s.../near/187253936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Why.20aren&#x27;t.20.60extern.20.22C.22.20fn.60.20declarations.20checked.20for.20FFI.20s.2E.2E.2E.html#187253936">(Feb 03 2020 at 11:33)</a>:</h4>
<p>That was added recently and it had too many (arguably) false positives in real world code so it was reverted for now</p>



<a name="187253998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Why%20aren%27t%20%60extern%20%22C%22%20fn%60%20declarations%20checked%20for%20FFI%20s.../near/187253998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Why.20aren&#x27;t.20.60extern.20.22C.22.20fn.60.20declarations.20checked.20for.20FFI.20s.2E.2E.2E.html#187253998">(Feb 03 2020 at 11:34)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/66220" target="_blank" title="https://github.com/rust-lang/rust/issues/66220">https://github.com/rust-lang/rust/issues/66220</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>